package netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 初始化器，channel注册后，会执行里面的初始化方法
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        //获得对应的管道
        ChannelPipeline pipeline = channel.pipeline();

        //通过管道，添加handler处理器
        //请求到客户端，需要做解码，相应到客户端做编码
        pipeline.addLast("httpServerCodec",new HttpServerCodec());
        //自定义的助手类，当请求访问，返回"hello"
        pipeline.addLast("httpHandler",new HttpHandler());
    }
}
